-- POCOR-3694
-- system_patches
INSERT INTO `system_patches` (`issue`, `created`) VALUES('POCOR-3694', NOW());

TRUNCATE TABLE `system_updates`;
INSERT INTO `system_updates` (`id`, `version`, `date_released`, `date_approved`, `approved_by`, `status`, `modified_user_id`, `modified`, `created_user_id`, `created`) VALUES
(1, '3.0.6', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 00:00:00'),
(2, '3.0.8', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 00:00:00'),
(3, '3.0.9', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 00:00:00'),
(4, '3.1.1', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 00:00:00'),
(5, '3.1.2', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 00:00:00'),
(6, '3.1.3', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 00:00:00'),
(7, '3.1.4', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 00:00:00'),
(8, '3.1.5', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 00:00:00'),
(9, '3.2.1', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 00:00:00'),
(10, '3.2.2', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 00:00:00'),
(11, '3.2.3', '2015-10-15', '2015-10-15', 1, 2, NULL, NULL, 1, '2015-10-15 18:00:08'),
(12, '3.2.4', '2015-10-21', '2015-10-21', 1, 2, NULL, NULL, 1, '2015-10-21 08:49:59'),
(13, '3.2.5', '2015-10-23', '2015-10-23', 1, 2, NULL, NULL, 1, '2015-10-23 09:11:54'),
(14, '3.2.6', '2015-10-25', '2015-10-25', 1, 2, NULL, NULL, 1, '2015-10-25 12:10:13'),
(15, '3.2.7', '2015-10-29', '2015-10-29', 1, 2, NULL, NULL, 1, '2015-10-29 12:40:47'),
(16, '3.2.10', '2015-11-05', '2015-11-05', 1, 2, NULL, NULL, 1, '2015-11-05 16:49:50'),
(17, '3.3.1', '2015-11-06', '2015-11-06', 1, 2, NULL, NULL, 1, '2015-11-06 11:26:59'),
(18, '3.3.4', '2015-12-02', '2015-12-02', 1, 2, NULL, NULL, 1, '2015-12-02 11:08:14'),
(19, '3.3.5', '2015-12-02', '2015-12-02', 1, 2, NULL, NULL, 1, '2015-12-02 11:08:22'),
(20, '3.3.6', '2015-12-02', '2015-12-02', 1, 2, NULL, NULL, 1, '2015-12-02 12:57:56'),
(21, '3.3.7', '2015-12-15', '2015-12-15', 1, 2, NULL, NULL, 1, '2015-12-15 15:41:55'),
(22, '3.3.8', '2015-12-15', '2015-12-15', 1, 2, NULL, NULL, 1, '2015-12-15 15:42:02'),
(23, '3.4.1', '2015-12-24', '2015-12-24', 1, 2, NULL, NULL, 1, '2015-12-24 10:28:49'),
(24, '3.4.2', '2015-12-24', '2015-12-24', 1, 2, NULL, NULL, 1, '2015-12-24 10:30:17'),
(25, '3.4.3', '2015-12-30', '2015-12-30', 1, 2, NULL, NULL, 1, '2015-12-30 09:12:18'),
(26, '3.4.4', '2015-12-31', '2015-12-31', 1, 2, NULL, NULL, 1, '2015-12-31 12:22:43'),
(27, '3.4.5', '2016-01-05', '2016-01-05', 1, 2, NULL, NULL, 1, '2016-01-05 13:10:00'),
(28, '3.4.6', '2016-01-07', '2016-01-07', 1, 2, NULL, NULL, 1, '2016-01-07 13:34:28'),
(29, '3.4.7', '2016-01-12', '2016-01-12', 1, 2, NULL, NULL, 1, '2016-01-12 16:03:32'),
(30, '3.4.8', '2016-01-15', '2016-01-15', 1, 2, NULL, NULL, 1, '2016-01-15 10:45:50'),
(31, '3.4.9', '2016-01-15', '2016-01-15', 1, 2, NULL, NULL, 1, '2016-01-15 18:51:48'),
(32, '3.4.10', '2016-01-20', '2016-01-20', 1, 2, NULL, NULL, 1, '2016-01-20 18:01:27'),
(33, '3.4.11', '2016-01-29', '2016-01-29', 1, 2, NULL, NULL, 1, '2016-01-29 17:17:06'),
(34, '3.4.12', '2016-02-05', '2016-02-05', 1, 2, NULL, NULL, 1, '2016-02-05 16:02:03'),
(35, '3.4.13', '2016-02-12', '2016-02-12', 1, 2, NULL, NULL, 1, '2016-02-12 18:29:35'),
(36, '3.4.14', '2016-02-22', '2016-02-22', 1, 2, NULL, NULL, 1, '2016-02-22 18:52:27'),
(37, '3.4.15', '2016-03-02', '2016-03-02', 1, 2, NULL, NULL, 1, '2016-03-02 17:53:33'),
(38, '3.4.15.1', '2016-03-09', '2016-03-09', 1, 2, NULL, NULL, 1, '2016-03-09 02:13:22'),
(39, '3.4.16', '2016-03-10', '2016-03-10', 1, 2, NULL, NULL, 1, '2016-03-10 10:30:41'),
(40, '3.4.17', '2016-03-18', '2016-03-18', 1, 2, NULL, NULL, 1, '2016-03-18 01:57:26'),
(41, '3.4.18', '2016-03-31', '2016-03-31', 1, 2, NULL, NULL, 1, '2016-03-31 06:01:08'),
(42, '3.4.18.2', '2016-04-15', '2016-04-15', 1, 2, NULL, NULL, 1, '2016-04-15 10:45:45'),
(43, '3.5.1', '2016-04-15', '2016-04-15', 1, 2, NULL, NULL, 1, '2016-04-15 10:45:44'),
(44, '3.5.2', '2016-04-20', '2016-04-20', 1, 2, NULL, NULL, 1, '2016-04-20 07:23:40'),
(45, '3.5.3', '2016-04-26', '2016-04-26', 1, 2, NULL, NULL, 1, '2016-04-26 09:05:27'),
(46, '3.5.4', '2016-05-06', '2016-05-06', 1, 2, NULL, NULL, 1, '2016-05-06 09:32:46'),
(47, '3.5.5', '2016-05-13', '2016-05-13', 1, 2, NULL, NULL, 1, '2016-05-13 10:28:09'),
(48, '3.5.5.2', '2016-06-01', '2016-06-01', 1, 2, NULL, NULL, 1, '2016-06-01 03:35:31'),
(49, '3.5.6', '2016-06-01', '2016-06-01', 1, 2, NULL, NULL, 1, '2016-06-01 03:35:51'),
(50, '3.5.6.1', '2016-06-10', '2016-06-10', 1, 2, NULL, NULL, 1, '2016-06-10 09:57:17'),
(51, '3.5.7', '2016-06-10', '2016-06-10', 1, 2, NULL, NULL, 1, '2016-06-10 09:57:20'),
(52, '3.5.8', '2016-06-17', '2016-06-17', 1, 2, NULL, NULL, 1, '2016-06-17 02:53:03'),
(53, '3.5.9.3', '2016-07-12', '2016-07-12', 1, 2, NULL, NULL, 1, '2016-07-12 09:06:40'),
(54, '3.5.10', '2016-07-12', '2016-07-12', 1, 2, NULL, NULL, 1, '2016-07-12 09:07:19'),
(55, '3.5.10.2', '2016-07-21', '2016-07-21', 1, 2, NULL, NULL, 1, '2016-07-21 07:23:11'),
(56, '3.5.11', '2016-07-21', '2016-07-21', 1, 2, NULL, NULL, 1, '2016-07-21 07:23:18'),
(57, '3.5.12', '2016-08-03', '2016-08-03', 1, 2, NULL, NULL, 1, '2016-08-03 07:02:11'),
(58, '3.6.1', '2016-08-17', '2016-08-17', 1, 2, NULL, NULL, 1, '2016-08-17 10:07:03'),
(59, '3.6.2', '2016-08-31', '2016-08-31', 1, 2, NULL, NULL, 1, '2016-08-31 07:06:46'),
(60, '3.6.2.1', '2016-09-07', '2016-09-07', 1, 2, NULL, NULL, 1, '2016-09-07 06:52:04'),
(61, '3.6.3', '2016-09-13', '2016-09-13', 1, 2, NULL, NULL, 1, '2016-09-13 05:53:53'),
(62, '3.6.4', '2016-09-26', '2016-09-26', 1, 2, NULL, NULL, 1, '2016-09-26 04:17:28'),
(63, '3.6.4.1', '2016-09-27', '2016-09-27', 1, 2, NULL, NULL, 1, '2016-09-27 08:52:12'),
(64, '3.6.5', '2016-09-30', '2016-09-30', 1, 2, NULL, NULL, 1, '2016-09-30 07:52:49'),
(65, '3.6.5.1', '2016-10-07', '2016-10-07', 1, 2, NULL, NULL, 1, '2016-10-07 02:19:57'),
(66, '3.6.6', '2016-10-07', '2016-10-07', 1, 2, NULL, NULL, 1, '2016-10-07 07:28:15'),
(67, '3.6.7', '2016-10-14', '2016-10-14', 1, 2, NULL, NULL, 1, '2016-10-14 06:16:09'),
(68, '3.7.1', '2016-10-24', '2016-10-24', 1, 2, NULL, NULL, 1, '2016-10-24 10:19:01'),
(69, '3.7.1.1', '2016-10-26', '2016-10-26', 1, 2, NULL, NULL, 1, '2016-10-26 01:24:05'),
(70, '3.7.1.2', '2016-10-26', '2016-10-26', 1, 2, NULL, NULL, 1, '2016-10-26 09:35:01'),
(71, '3.7.2', '2016-11-08', '2016-11-08', 1, 2, NULL, NULL, 1, '2016-11-08 07:25:03'),
(72, '3.7.3', '2016-11-11', '2016-11-11', 1, 2, NULL, NULL, 1, '2016-11-11 08:26:47'),
(73, '3.7.4', '2016-11-18', '2016-11-18', 1, 2, NULL, NULL, 1, '2016-11-18 09:51:29'),
(74, '3.7.5', '2016-11-25', '2016-11-25', 1, 2, NULL, NULL, 1, '2016-11-25 10:01:55'),
(75, '3.8.1', '2016-12-05', '2016-12-05', 1, 2, NULL, NULL, 1, '2016-12-05 09:30:00'),
(76, '3.8.1.1', '2016-12-09', '2016-12-09', 1, 2, NULL, NULL, 1, '2016-12-09 10:47:52'),
(77, '3.8.2', '2016-12-16', '2016-12-16', 1, 2, NULL, NULL, 1, '2016-12-16 11:37:22'),
(78, '3.8.3', '2016-12-23', '2016-12-23', 1, 2, NULL, NULL, 1, '2016-12-23 04:30:46'),
(79, '3.8.4', '2017-01-03', '2017-01-03', 1, 2, NULL, NULL, 1, '2017-01-03 10:12:18');


-- 3.8.4.1
UPDATE config_items SET value = '3.8.4.1' WHERE code = 'db_version';
UPDATE system_patches SET version = (SELECT value FROM config_items WHERE code = 'db_version') WHERE version IS NULL;
SET @maxId := 0;
SELECT max(id) + 1 INTO @maxId FROM system_updates;
INSERT IGNORE INTO system_updates (id, version, date_released, date_approved, approved_by, status, created) VALUES
(
  @maxId,
  (SELECT value FROM config_items WHERE code = 'db_version'),
  NOW(), NOW(), 1, 2, NOW()
);
